package com.group9.handinhand.dao.model;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.group9.handinhand.service.so.UserTagSO;

@Entity
@Table(name = "USER_TAG", uniqueConstraints = @UniqueConstraint(columnNames = { "TAG_ID", "USER_ID" }))
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class UserTag extends AbstractBaseModel {
	
	private static final long serialVersionUID = 1L;
    
	@ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "TAG_ID", nullable = false)
    private Tag tag;
	
	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "USER_ID", nullable = false)
	private User user;
	
	public UserTagSO convertToServiceObject() {
		UserTagSO so = (UserTagSO) convert(new UserTagSO());
		so.setUser(this.user.convertToServiceObject());
		so.setTag(this.tag.convertToServiceObject());
		return so;
	}

	public Tag getTag() {
		return tag;
	}
	public void setTag(Tag tag) {
		this.tag = tag;
	}
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	@Override
	public String toString() {
		return "UserTag [tag=" + tag + ", user=" + user + "]";
	}
	
	

}
